﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;

using CoolCode.Security;
using CoolCode.Services;
using CoolCode.Caching;
using CoolCode.Ioc;

namespace CoolCode.Web.UI
{
    /// <summary>
    ///  
    /// </summary>
    public abstract partial class BasePage : System.Web.UI.Page, IPage, IControl, IControlBindable
    {
        #region Properties

        public virtual string UserName
        {
            get { return this.User.Identity.Name; }
        }

        public new ICache Cache
        {
            get
            {
                return new WebCacheStrategy();
                //(ICache ) CacheFactory.CreateInstance(); 
            }
        }


        #endregion

        #region Validating

        //public void DisplayMessage(string code, MessageType type)
        //{

        //}


        //public void DisplayMessage(string code, string msg, MessageType type)
        //{

        //}

        //public void DisplayMessage(Exception exp)
        //{

        //}

        //public virtual void FinalCheck(string validationGroup)
        //{

        //}

        //public override void Validate(string validationGroup)
        //{
        //    try
        //    {
        //        this.PassValidation = true;
        //        base.Validate(validationGroup);
        //        this.FinalCheck(validationGroup);
        //    }
        //    catch (Exception exp)
        //    {
        //        this.PassValidation = false;
        //        this.HandleError(exp);
        //    }
        //}

        //public virtual void HandleError(Exception exp)
        //{
        //}

        //public virtual bool PassValidation
        //{
        //    get;
        //    private set;
        //}

        #endregion

        #region IControlBindable Members

        public virtual IControlBinder ControlBinder
        {
            get { return new ControlBinder(); }
        }

        #endregion

        protected static readonly IDiggable Digger = new Combiner(InjectTable.Injector);

        //internal class DefaultInjector : Injector
        //{
        //    public override void Inject()
        //    {
        //        Link<IControlBinder, ControlBinder>();
        //    }
        //}
    }
}
